package cn.wolfcode.wolf2w.controller;

import cn.wolfcode.wolf2w.domain.ScenicSpot;
import cn.wolfcode.wolf2w.service.IScenicSpotService;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* 景点控制层
*/
@RestController
@RequestMapping("scenicSpot")
public class ScenicSpotController {

    @Autowired
    private IScenicSpotService scenicSpotService;

    @GetMapping("/list")
    public Object list(){
        List<ScenicSpot> list = scenicSpotService.list();
        return list;
    }

    @RequestMapping("/get")
    @ResponseBody
    public Object get(String id){
        return JsonResult.success(scenicSpotService.get(id));
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(ScenicSpot scenicSpot){

        scenicSpotService.saveOrUpdate(scenicSpot);

        return JsonResult.success();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(String id){
        scenicSpotService.delete(id);
        return JsonResult.success();
    }
}
